#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include <iostream>
#include <string.h>
#include <assert.h>

using namespace std;

namespace XW
{
	class string
	{
	public:
		typedef char* iterator;
		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}

		string(const char* str = "");
		string(size_t n, char ch);
		string(const string& s);
		char& operator[](size_t i);
		size_t capacity();
		const char& operator[](size_t i)const;
		size_t size();
		const char* c_str()const;
		void reserve(size_t n);
		void push_back(char ch);
		void append(const char* str);
		void insert(size_t pos, size_t n, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);
		size_t find(char ch, size_t pos = 0);
		size_t find(const char* str, size_t pos = 0);
		string substr(size_t pos,size_t len);

		string& operator=(string& s);
		string& operator+=(char ch);
		string& operator+=(const char* str);

		void clear()
		{
			_str[0] = '\0';
			_size = 0;
		}

		~string();
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
		const static size_t npos;
	};

	ostream& operator<<(ostream& out, string& s);
	istream& operator>>(istream& in, string& s);

}




void test1();
void test2();
void test3();